Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.Entity
Imports System.Linq
Imports System.Net
Imports System.Web
Imports System.Web.Mvc
Imports PagedList
Imports PagedList.Mvc

Public Class <OwnerU>_<TableU>Controller
    Inherits Controller
    Private db As New <Database>DBContext()
        
    ' GET: /<OwnerU>_<TableU>/
    Public Function Index() As ActionResult
        Return View(db.<OwnerU>_<TableU>.ToList())
    End Function

    ' GET: /<OwnerU>_<TableU>/Details/<id>
    Public Function Details(
    <If Loop>
      <IsPKey>
      <And>
      <IsNullable>
      <And>
      <IsCurRow=[0]>
                           <FieldU> As Nullable(Of <VBType>) _
      <IsPKey>
      <And>
      <IsNullable>
      <And>
      <IsCurRow<>[0]>
                          ,<FieldU> As Nullable(Of <VBType>) _
      <IsPKey>
      <And>
      <IsNotNullable>
      <And>
      <IsCurRow=[0]>
                           <FieldU> As <VBType> _
      <IsPKey>
      <And>
      <IsNotNullable>
      <And>
      <IsCurRow<>[0]>
                          ,<FieldU> As <VBType> _
    </If Loop>
                           ) As ActionResult

    <If Loop>
      <IsPKey>
        If _
        <ExitLoop>
    </If Loop>
    <If Loop>
      <IsPKey>
      <And>
      <IsCurRow=[0]>
            <FieldU> Is Nothing _
      <IsPKey>
      <And>
      <IsCurRow<>[0]>
            Or <FieldU> Is Nothing _
    </If Loop>
    <If Loop>
      <IsPKey>
        Then
            Return New HttpStatusCodeResult(HttpStatusCode.BadRequest)
        End If
        Dim <OwnerU>_<TableU> As <OwnerU>_<TableU> = db.<OwnerU>_<TableU>.Find(
        <ExitLoop>
    </If Loop>
    <If Loop>
      <IsPKey>
      <And>
      <IsCurRow=[0]>
                                                 <FieldU> _
      <IsPKey>
      <And>
      <IsCurRow<>[0]>
                                                ,<FieldU> _
    </If Loop>
                                            )
    <If Loop>
      <IsPKey>
        If <OwnerU>_<TableU> Is Nothing Then
            Return HttpNotFound()
        End If
        Return View(<OwnerU>_<TableU>)
    End Function
        <ExitLoop>
    </If Loop>

    ' GET: /<OwnerU>_<TableU>/Create
    Public Function Create() As ActionResult
    <If Loop>
      <IsFKey>
        ' ComboBox
      <ExitLoop>
    </If Loop>
    <If Loop>
    	<IsFKey>
        ViewBag.<RFieldU> = New SelectList(db.<ROwnerU>_<RTableU>, "<RFieldU>", "<RDisplayFieldU>")
    </If Loop>

        Return View()
    End Function

    ' POST: /<OwnerU>_<TableU>/Create
    ' To protect from overposting attacks, please enable the specific properties you want to bind to, for 
    ' more details see http://go.microsoft.com/fwlink/?LinkId=317598.
    <HttpPost> _
    <ValidateAntiForgeryToken> _
    Public Function Create(<Bind(Include:=
		            <If Loop>
		               <IsNotIdentity>
                           <SF[+ "," + ]>"<Field>" _
		            </If Loop>
				  )> <OwnerU>_<TableU> As <OwnerU>_<TableU>) As ActionResult
        If ModelState.IsValid Then
            db.<OwnerU>_<TableU>.Add(<OwnerU>_<TableU>)
            db.SaveChanges()
            Return RedirectToAction("Index")
        End If
    <If Loop>
      <IsFKey>
        ' ComboBox
      <ExitLoop>
    </If Loop>
    <If Loop>
    	<IsFKey>
        ViewBag.<RFieldU> = New SelectList(db.<ROwnerU>_<RTableU>, "<RFieldU>", "<RDisplayFieldU>", <OwnerU>_<TableU>.<FieldU>)
    </If Loop>

        Return View(<OwnerU>_<TableU>)
    End Function

    ' GET: /<OwnerU>_<TableU>/Edit/<id>
    Public Function Edit(
    <If Loop>
      <IsPKey>
      <And>
      <IsNullable>
      <And>
      <IsCurRow=[0]>
                        <FieldU> As Nullable(Of <VBType>) _
      <IsPKey>
      <And>
      <IsNullable>
      <And>
      <IsCurRow<>[0]>
                       ,<FieldU> As Nullable(Of <VBType>) _
      <IsPKey>
      <And>
      <IsNotNullable>
      <And>
      <IsCurRow=[0]>
                        <FieldU> As <VBType> _
      <IsPKey>
      <And>
      <IsNotNullable>
      <And>
      <IsCurRow<>[0]>
                       ,<FieldU> As <VBType> _
    </If Loop>
                        ) As ActionResult

    <If Loop>
      <IsPKey>
        If _
        <ExitLoop>
    </If Loop>
    <If Loop>
      <IsPKey>
      <And>
      <IsCurRow=[0]>
            <FieldU> Is Nothing _
      <IsPKey>
      <And>
      <IsCurRow<>[0]>
            Or <FieldU> Is Nothing _
    </If Loop>
    <If Loop>
      <IsPKey>
        Then
            Return New HttpStatusCodeResult(HttpStatusCode.BadRequest)
        End If
        Dim <OwnerU>_<TableU> As <OwnerU>_<TableU> = db.<OwnerU>_<TableU>.Find(
        <ExitLoop>
    </If Loop>
    <If Loop>
      <IsPKey>
      <And>
      <IsCurRow=[0]>
                                                 <FieldU> _
      <IsPKey>
      <And>
      <IsCurRow<>[0]>
                                                ,<FieldU> _
    </If Loop>
                                            )
    <If Loop>
      <IsPKey>
        If <OwnerU>_<TableU> Is Nothing Then
            Return HttpNotFound()
        End If
        <ExitLoop>
    </If Loop>
    <If Loop>
      <IsFKey>
        ' ComboBox
      <ExitLoop>
    </If Loop>
    <If Loop>
    	<IsFKey>
        ViewBag.<RFieldU> = New SelectList(db.<ROwnerU>_<RTableU>, "<RFieldU>", "<RDisplayFieldU>", <OwnerU>_<TableU>.<FieldU>)
    </If Loop>

    <If Loop>
      <IsPKey>
        Return View(<OwnerU>_<TableU>)
    End Function
        <ExitLoop>
    </If Loop>

    ' POST: /<OwnerU>_<TableU>/Edit/<id>
    ' To protect from overposting attacks, please enable the specific properties you want to bind to, for 
    ' more details see http://go.microsoft.com/fwlink/?LinkId=317598.
    <HttpPost, ActionName("Edit")> _
    <ValidateAntiForgeryToken> _
    Public Function Edit(<OwnerU>_<TableU> As <OwnerU>_<TableU>) As ActionResult

        If ModelState.IsValid Then
            db.Entry(<OwnerU>_<TableU>).State = EntityState.Modified
            db.SaveChanges()
            Return RedirectToAction("Index")
        End If

    <If Loop>
      <IsFKey>
        ' ComboBox
      <ExitLoop>
    </If Loop>
    <If Loop>
    	<IsFKey>
        ViewBag.<RFieldU> = New SelectList(db.<ROwnerU>_<RTableU>, "<RFieldU>", "<RDisplayFieldU>", <OwnerU>_<TableU>.<FieldU>)
    </If Loop>

        Return View(<OwnerU>_<TableU>)
    End Function

    ' GET: /<OwnerU>_<TableU>/Delete/<id>
    Public Function Delete(
    <If Loop>
      <IsPKey>
      <And>
      <IsNullable>
      <And>
      <IsCurRow=[0]>
                           <FieldU> As Nullable(Of <VBType>) _
      <IsPKey>
      <And>
      <IsNullable>
      <And>
      <IsCurRow<>[0]>
                          ,<FieldU> As Nullable(Of <VBType>) _
      <IsPKey>
      <And>
      <IsNotNullable>
      <And>
      <IsCurRow=[0]>
                           <FieldU> As <VBType> _
      <IsPKey>
      <And>
      <IsNotNullable>
      <And>
      <IsCurRow<>[0]>
                          ,<FieldU> As <VBType> _
    </If Loop>
                           ) As ActionResult

    <If Loop>
      <IsPKey>
        If _
        <ExitLoop>
    </If Loop>
    <If Loop>
      <IsPKey>
      <And>
      <IsCurRow=[0]>
            <FieldU> Is Nothing _
      <IsPKey>
      <And>
      <IsCurRow<>[0]>
            Or <FieldU> Is Nothing _
    </If Loop>
    <If Loop>
      <IsPKey>
        Then
            Return New HttpStatusCodeResult(HttpStatusCode.BadRequest)
        End If
        Dim <OwnerU>_<TableU> As <OwnerU>_<TableU> = db.<OwnerU>_<TableU>.Find(
        <ExitLoop>
    </If Loop>
    <If Loop>
      <IsPKey>
      <And>
      <IsCurRow=[0]>
                                                 <FieldU> _
      <IsPKey>
      <And>
      <IsCurRow<>[0]>
                                                ,<FieldU> _
    </If Loop>
                                            )
    <If Loop>
      <IsPKey>
        If <OwnerU>_<TableU> Is Nothing Then
            Return HttpNotFound()
        End If
        Return View(<OwnerU>_<TableU>)
    End Function
        <ExitLoop>
    </If Loop>

    ' POST: /<OwnerU>_<TableU>/Delete/<id>
    <HttpPost, ActionName("Delete")> _
    <ValidateAntiForgeryToken> _
    Public Function DeleteConfirmed(
    <If Loop>
      <IsPKey>
      <And>
      <IsNullable>
      <And>
      <IsCurRow=[0]>
                                   <FieldU> As Nullable(Of <VBType>) _
      <IsPKey>
      <And>
      <IsNullable>
      <And>
      <IsCurRow<>[0]>
                                  ,<FieldU> As Nullable(Of <VBType>) _
      <IsPKey>
      <And>
      <IsNotNullable>
      <And>
      <IsCurRow=[0]>
                                   <FieldU> As <VBType> _
      <IsPKey>
      <And>
      <IsNotNullable>
      <And>
      <IsCurRow<>[0]>
                                  ,<FieldU> As <VBType> _
    </If Loop>
                                   ) As ActionResult
    <If Loop>
      <IsPKey>

        Dim <OwnerU>_<TableU> As <OwnerU>_<TableU> = db.<OwnerU>_<TableU>.Find(
        <ExitLoop>
    </If Loop>
    <If Loop>
      <IsPKey>
      <And>
      <IsCurRow=[0]>
                                                 <FieldU> _
      <IsPKey>
      <And>
      <IsCurRow<>[0]>
                                                ,<FieldU> _
    </If Loop>
                                            )
    <If Loop>
      <IsPKey>
        db.<OwnerU>_<TableU>.Remove(<OwnerU>_<TableU>)
        db.SaveChanges()
        Return RedirectToAction("Index")
    End Function
        <ExitLoop>
    </If Loop>

    Protected Overrides Sub Dispose(disposing As Boolean)
        If disposing Then
            db.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub
End Class
